package sns.service;

import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import sns.bean.Impression;
import sns.bean.Relation;
import sns.bean.User;
import sns.dao.ImpressionDao;

@Transactional
public class ImpressionService {
	
	private ImpressionDao impressionDao;
	
	/**
	 * get impression by its id
	 * 
	 * @param idimpression
	 * @return
	 */
	public Impression getImpressionById(Long idimpression){
		return impressionDao.getImpressionById(idimpression);
	}
	
	/**
	 * get impressions of the user
	 * 
	 * @param user
	 * @return
	 */
	public List<Impression> getImpressionsOfUser(User user){
		return impressionDao.getImpressionsOfUser(user);
	}
	
	/**
	 * get the impressions by relation
	 * @param relation
	 * @return
	 */
	public List<Impression> getImpressionsByRelation(Relation relation){
		return impressionDao.getImpressionsByRelation(relation);
	}
	
	/**
	 * delete all the impressions of the relation
	 * @param relation
	 * @return
	 */
	public boolean deleteImpressionByRelation(Relation relation){
		List<Impression> impressions = getImpressionsByRelation(relation);
		for(Impression impression:impressions){
			impressionDao.delete(impression);
		}
		return true;
	}

	public void setImpressionDao(ImpressionDao impressionDao) {
		this.impressionDao = impressionDao;
	}
}
